Page({
  data: {
    productList: [
      {
        id: 1,
        name: "示例商品1",
        price: 10.99,
        image: "https://via.placeholder.com/150",
        recommend: true
      },
      {
        id: 2,
        name: "示例商品2",
        price: 15.99,
        image: "https://via.placeholder.com/150",
        recommend: false
      }
    ]
  },
  
  onLoad() {
    this.loadProducts();
  },
  
  loadProducts() {
    // 从服务器获取商品列表
    // 这里使用模拟数据
  },
  
  addProduct() {
    wx.navigateTo({
      url: '/pages/product/edit/edit'
    });
  },
  
  editProduct(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/product/edit/edit?id=${id}`
    });
  },
  
  deleteProduct(e) {
    const id = e.currentTarget.dataset.id;
    wx.showModal({
      title: '提示',
      content: '确定要删除这个商品吗?',
      success: (res) => {
        if (res.confirm) {
          // 调用API删除商品
          this.setData({
            productList: this.data.productList.filter(item => item.id !== id)
          });
        }
      }
    });
  }
})